<?php


class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onmemberattlist() {
		$this->powercheck(115, 116);
		parent::start_template();
		$MinPageid = $this->fun->accept('MinPageid', 'R');

		$page_id = $this->fun->accept('page_id', 'R');

		$countnum = $this->fun->accept('countnum', 'R');

		$MaxPerPage = $this->fun->accept('MaxPerPage', 'R');
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}
		$wheretext = null;
		$isclass = $this->fun->accept('isclass', 'R');
		if (!empty($isclass)) {
			if ($isclass == 2) $isclass = 0;
			$wheretext.=' AND isclass=' . $isclass;
		}
		$isvalidate = $this->fun->accept('isvalidate', 'R');
		if (!empty($isvalidate)) {
			if ($isvalidate == 2) $isvalidate = 0;
			$wheretext.=' AND isvalidate=' . $isvalidate;
		}
		$isline = $this->fun->accept('isline', 'R');
		if (!empty($isline)) {
			if ($isline == 2) $isline = 0;
			$wheretext.=' AND isline=' . $isline;
		}

		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'maid' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_where = " WHERE maid>0" . $wheretext;
		$db_table = db_prefix . 'member_attr';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT maid,pid,typename,attrname,inputtype,attrvalue,validatetext,attrcue,attrsize,attrrow,attrlenther,isclass,isvalidate,isline FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('sql', $sql);
		$this->ectemplates->display('member/mematt_list');
	}

	function onmodelpreview() {
		parent::start_template();
		$db_table = db_prefix . 'model';
		$id = $this->fun->accept('id', 'G');
		$db_where = 'mid=' . $id;
		$modelread = $this->db->fetch_first('SELECT * FROM ' . $db_table . ' WHERE ' . $db_where);

		$db_where = ' WHERE isclass=1 and mid=' . $modelread['mid'] . ' ORDER BY pid';
		$db_table = db_prefix . 'model_att';
		$sql = 'SELECT * FROM ' . $db_table . $db_where;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			if ($rsList['inputtype'] == 'select' || $rsList['inputtype'] == 'radio' || $rsList['inputtype'] == 'checkbox') {
				$forvalue = split("\n", $rsList['attrvalue']);
				$newvalue = array();
				foreach ($forvalue as $key => $forvalue) {
					if ($key == 0) {
						$newvalue[] = array('name' => $forvalue, 'selected' => 'selected');
					} else {
						$newvalue[] = array('name' => $forvalue, 'selected' => '');
					}
				}
				$rsList['attrvalue'] = $newvalue;
			}
			$attrread[] = $rsList;
		}
		$this->ectemplates->assign('modelread', $modelread);
		$this->ectemplates->assign('attrread', $attrread);
		$this->ectemplates->display('article/model_preview');
	}

	function onmemattadd() {
		include_once admin_ROOT . adminfile . '/include/inc_formtypelist.php';
		parent::start_template();
		$tab = $this->fun->accept('tab', 'G');
		$tab = empty($tab) ? 'true' : $tab;
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('formtypelist', $FORMTYPE);
		$this->ectemplates->display('member/memattr_add');
	}

	function onmemattedit() {
		include_once admin_ROOT . adminfile . '/include/inc_formtypelist.php';
		parent::start_template();
		$db_table = db_prefix . 'member_attr';
		$maid = $this->fun->accept('maid', 'G');
		$db_where = 'maid=' . $maid;
		$attrread = $this->db->fetch_first('SELECT * FROM ' . $db_table . ' WHERE ' . $db_where);
		$this->ectemplates->assign('tab', 'true');
		$this->ectemplates->assign('formtypelist', $FORMTYPE);
		$this->ectemplates->assign('attrread', $attrread);
		$this->ectemplates->display('member/memattr_edit');
	}

	function onattsave() {
		parent::start_template();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$typename = $this->fun->accept('typename', 'P');
		$attrname = $this->fun->accept('attrname', 'P');
		$attrcue = $this->fun->accept('attrcue', 'P');
		$inputtype = $this->fun->accept('inputtype', 'P');
		$attrvalue = $this->fun->accept('attrvalue', 'P');
		$attrsize = $this->fun->accept('attrsize', 'P');
		$attrsize = empty($attrsize) ? 20 : $attrsize;
		$attrrow = $this->fun->accept('attrrow', 'P');
		$attrrow = empty($attrrow) ? 5 : $attrrow;
		$attrlenther = $this->fun->accept('attrlenther', 'P');
		$attrlenther = empty($attrlenther) ? 50 : $attrlenther;
		$validatetext = $this->fun->accept('validatetext', 'P');
		$isvalidate = $this->fun->accept('isvalidate', 'P');
		$isline = $this->fun->accept('isline', 'P');
		$db_table = db_prefix . 'member_attr';
		if ($inputclass == 'add') {
			$this->powercheck(115, 117);
			$db_field = 'pid,typename,attrname,inputtype,attrvalue,validatetext,attrcue,attrsize,attrrow,attrlenther,isclass,isvalidate,isline';
			$db_values = "50,'$typename','$attrname','$inputtype','$attrvalue','$validatetext','$attrcue',$attrsize,$attrrow,$attrlenther,1,$isvalidate,$isline";
			$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			$this->writelog($this->lng['memattmanage_add'], $this->lng['log_extra_ok'] . ' typename=' . $typename);
			$this->dbcache->clearcache('memberatt_array', true);
			exit('true');
		} elseif ($inputclass == 'edit') {
			$this->powercheck(115, 134);
			$maid = $this->fun->accept('maid', 'P');
			$db_where = 'maid=' . $maid;
			$db_set = "typename='$typename',attrcue='$attrcue',validatetext='$validatetext',inputtype='$inputtype',attrvalue='$attrvalue',attrsize=$attrsize,attrrow=$attrrow,attrlenther=$attrlenther,isvalidate=$isvalidate,isline=$isline";
			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$this->writelog($this->lng['memattmanage_edit'], $this->lng['log_extra_ok'] . ' typename=' . $typename . ' id=' . $id);
			$this->dbcache->clearcache('memberatt_array', true);
			exit('true');
		}
	}

	function ondel() {
		$this->powercheck(115, 131);
		$db_table = db_prefix . 'member_attr';
		$selectinfoid = $this->fun->accept('selectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "maid=$infoarray[$i]";
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
		}
		$this->writelog($this->lng['memattmanage_log_del'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('memberatt_array', true);
		exit('true');
	}

	function onsort() {
		$this->powercheck(115, 132);
		$db_table = db_prefix . 'member_attr';
		$id = $this->fun->accept('infoid', 'P');
		$pid = $this->fun->accept('pid', 'P');
		$idArray = explode(',', $id);
		$pidArray = explode(',', $pid);
		foreach ($idArray as $key => $value) {
			if (!empty($value)) {
				$db_where = "maid=$value";
				$pid = intval($pidArray[$key]);
				$db_set = "pid=$pid";
				$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			}
		}
		$this->writelog($this->lng['memattmanage_log_sort'], $this->lng['log_extra_ok']);
		$this->dbcache->clearcache('memberatt_array', true);
		exit('true');
	}

	function onsetting() {
		$this->powercheck(115, 133);
		$db_table = db_prefix . 'member_attr';
		$selectinfoid = $this->fun->accept('selectinfoid', 'P');
		$selectinfoid = $selectinfoid . '0';
		if (empty($selectinfoid)) exit('false');
		$value = $this->fun->accept('value', 'P');
		$dbname = $this->fun->accept('dbname', 'P');
		$db_set = "$dbname=$value";
		$db_where = "maid IN ( $selectinfoid )";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		$this->writelog($this->lng['memattmanage_log_istype'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('memberatt_array', true);
		exit('true');
	}

	function oncheckattrname() {
		$attlist = array('userid', 'username', 'password', 'email', 'question', 'answer', 'sex', 'birthday', 'country', 'province', 'city', 'district',
		    'alias', 'address', 'zipcode', 'tel', 'mobile', 'qq', 'msn', 'integral', 'visitcount', 'lastip', 'addtime', 'lasttime', 'mcid', 'isclass');
		$attrname = $this->fun->accept('attrname', 'R');
		$attrnamearray = strtolower($attrname);

		if (in_array($attrnamearray, $attlist)) {
			exit('false');
		}
		$db_table = db_prefix . 'member_attr';
		$db_where = " WHERE attrname='$attrname'";
		$countnum = $this->db_numrows($db_table, $db_where);
		if ($countnum > 0) {
			$exportAjax = 'false';
		} else {
			$exportAjax = 'true';
		}
		exit($exportAjax);
	}

}
?>